package com.czy.booktest02.demos.api.v1;

import com.czy.booktest02.demos.common.dtos.ResponseResult;
import com.czy.booktest02.demos.pojo.dto.UserDto;
import com.czy.booktest02.demos.pojo.dto.UserPermissionDto;
import com.czy.booktest02.demos.pojo.dto.UserStatusDto;
import com.czy.booktest02.demos.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;
    @PostMapping("/banByAdmin")
    public ResponseResult banByAdmin(@RequestParam("id") int id){
        return userService.banByAdmin(id);
    }

    @GetMapping("/selectAllUser")
    public ResponseResult selectAllUser(){
        return userService.selectAllUser();
    }

    /**
     * 启用或禁用用户
     */
    @PostMapping("/updateUserStatus")
    public ResponseResult updateUserStatus( @RequestBody UserStatusDto userStatusDto){
        return userService.updateUserStatus(userStatusDto.getId(),userStatusDto.isFlag());
    }

    /**
     * 逻辑删除用户
     */
    @PostMapping("/deleteUser")
    public ResponseResult deleteUser(@RequestParam("id")int id){
        return userService.deleteUser(id);
    }

    /**
     * 权限设置
     */
    @PostMapping("/setPermission")
    public ResponseResult setPermission(@RequestBody UserPermissionDto userPermissionDto){
        return userService.setPermission(userPermissionDto.getId(),userPermissionDto.getPermission());
    }
}
